﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UcAddToChuc.ascx.cs"
    Inherits="Viewer.ToChuc.UserControls.UcAddToChuc" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Register Src="~/ToChuc/UserControl/UCLookUpDiaChi.ascx" TagName="UCLookUpDiaChi"
    TagPrefix="uc" %>
<%@ Register Src="UCLookUpToChucHanhChinh.ascx" TagName="UCLookUpToChucHanhChinh"
    TagPrefix="uc" %>
<link href="../../resources/css/main.css" rel="stylesheet" type="text/css" />
<ext:XScript ID="XScipt1" runat="server">
    <script type="text/javascript">
    function InsertToChucHanhChinhTrucThuoc(id, name)
    {
        #{txtToChucHanhChinhTrucThuoc}.setValue(name);
        #{hdToChucHanhChinhTruocThuocID}.setValue(id);
    
    }
    function InsertEntity(number,name) { 
        
            #{hdDiaChiId}.setValue(number);
            #{txtDiaChi}.setValue(name);
        }
        function Validate()
        {       
        
            if(CheckData())
            {                       
               #{hdIdCha}.setValue(#{ccbToChucCha}.getValue());
                 #{hdXepHang}.setValue(#{cbbXepHang}.getValue());
                   #{hdKhoi}.setValue(#{cbbKhoi}.getValue());
            }
            else
            {
              Ext.MessageBox.alert('Lỗi', 'Bạn chưa nhập đủ các trường cần thiết!');
                                    #{txtFullName}.focus();
                                    return false;
            }
        }
        function CheckData()
        {
      
            if(#{txtFullName}.getValue()=='')
            {
                return false;
            }
           
             if(#{cbbXepHang}.getValue()=='')
            {
                return false;
            }
             if(#{cbbKhoi}.getValue()=='')
            {
                return false;
            }
             if(#{txtDiaChi}.getValue()=='')
            {
                return false;
            }
              if(#{txtGhiChu}.getValue()=='')
            {
                //return false;
            }
            
            if (#{cboLoaiToChuc}.getValue()=='')
            {
                return false;
            }
            return true;
        }
    </script>
</ext:XScript>
<ext:Window ID="wdAddNewToChuc" runat="server" Width="490" AutoHeight="true" Modal="true"
    Hidden="true" Title="Add New " Icon="User" BodyCssClass="window">
    <Items>
        <ext:Container ID="Container1" runat="server" Layout="FormLayout" Height="300" LabelWidth="150"
            LabelSeparator="">
            <Items>
                <ext:TextField ID="txtId" runat="server" ReadOnly="true" Width="50" Hidden="true" />
                <ext:TextField ID="txtShortName" runat="server" Width="300" FieldLabel=" Tên tổ chức (Short)" />
                <ext:TextField ID="txtFullName" runat="server" Width="300" FieldLabel=" Tên tổ chức (Full)" />
                <ext:Hidden ID="hdIdCha" runat="server" />
                <ext:ComboBox ID="ccbToChucCha" runat="server" ReadOnly="true" DisplayField="TenToChucFull"
                    ValueField="ToChucID" EmptyText="" FieldLabel="Tổ chức trực thuộc" Width="300">
                    <Store>
                        <ext:Store ID="storeTochuc" runat="server">
                            <Reader>
                                <ext:JsonReader IDProperty="ToChucID">
                                    <Fields>
                                        <ext:RecordField Name="ToChucID" />
                                        <ext:RecordField Name="TenToChucFull" />
                                    </Fields>
                                </ext:JsonReader>
                            </Reader>
                        </ext:Store>
                    </Store>
                    <Triggers>
                        <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                    </Triggers>
                    <Listeners>
                        <Select Handler="this.triggers[0].show();" />
                        <BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                        <TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
                    </Listeners>
                </ext:ComboBox>
                <ext:ComboBox ID="cbbXepHang" runat="server" DisplayField="CodeValue" ValueField="CodeID"
                    EmptyText="Chọn xếp hạng" FieldLabel=" Xếp hạng đơn vị" Width="300">
                    <Store>
                        <ext:Store ID="storeXepHang" runat="server">
                            <Reader>
                                <ext:JsonReader IDProperty="CodeID">
                                    <Fields>
                                        <ext:RecordField Name="CodeID" />
                                        <ext:RecordField Name="CodeValue" />
                                    </Fields>
                                </ext:JsonReader>
                            </Reader>
                        </ext:Store>
                    </Store>
                    <Triggers>
                        <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                    </Triggers>
                    <Listeners>
                        <Select Handler="this.triggers[0].show();" />
                        <BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                        <TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
                    </Listeners>
                </ext:ComboBox>
                <ext:ComboBox ID="cbbKhoi" runat="server" DisplayField="CodeValue" ValueField="CodeID"
                    EmptyText="Chọn khối" FieldLabel=" Khối quản lí" Width="300">
                    <Store>
                        <ext:Store ID="storeKhoi" runat="server">
                            <Reader>
                                <ext:JsonReader IDProperty="CodeID">
                                    <Fields>
                                        <ext:RecordField Name="CodeID" />
                                        <ext:RecordField Name="CodeValue" />
                                    </Fields>
                                </ext:JsonReader>
                            </Reader>
                        </ext:Store>
                    </Store>
                    <Triggers>
                        <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                    </Triggers>
                    <Listeners>
                        <Select Handler="this.triggers[0].show();" />
                        <BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                        <TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
                    </Listeners>
                </ext:ComboBox>
                <ext:TextField ID="txtDiaChi" runat="server" Width="300" ReadOnly="true" FieldLabel="Địa chỉ" />
                <ext:Container ID="Container2" runat="server" FieldLabel=" ">
                    <Items>
                        <ext:Hidden runat="server" ID="hdStatus" />
                        <ext:Hidden runat="server" ID="hdXepHang" />
                        <ext:Hidden runat="server" ID="hdKhoi" />
                        <ext:Hidden runat="server" ID="hdDiaChiId" />
                        <ext:Button ID="btnLookUp" runat="server" Icon="Magnifier" Text="Chọn địa chỉ" IconAlign="Right">
                            <DirectEvents>
                                <Click OnEvent="btnLookUp_Click">
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                    </Items>
                </ext:Container>
                <ext:Container ID="Container3" runat="server" Width="300" FieldLabel="Đơn vị hàn chính trực thuộc">
                    <Items>
                        <ext:TextField ID="txtToChucHanhChinhTrucThuoc" runat="server" Width="300" ReadOnly="true" />
                        <ext:Hidden runat="server" ID="hdToChucHanhChinhTruocThuocID" />
                        <ext:Button ID="btnLookUpToChucHanhChinhTrucThuoc" runat="server" Icon="Magnifier"
                            Text="Chọn tổ chức hành chính" IconAlign="Right">
                            <Listeners>
                                <Click Handler="#{wdLookUpToChucHanhChinh}.show();" />
                            </Listeners>
                        </ext:Button>
                    </Items>
                </ext:Container>
                <ext:Container ID="Container4" runat="server" Width="300" FieldLabel="Loại Tổ Chức">
                    <Items>
                        <ext:ComboBox ID="cboLoaiToChuc" runat="server" DisplayField="CodeValue" ValueField="CodeID"
                            EmptyText="Chọn loại tổ chức" Width="300">
                            <Store>
                                <ext:Store ID="storeLoaiToChuc" runat="server">
                                    <Reader>
                                        <ext:JsonReader IDProperty="CodeID">
                                            <Fields>
                                                <ext:RecordField Name="CodeID" />
                                                <ext:RecordField Name="CodeValue" />
                                            </Fields>
                                        </ext:JsonReader>
                                    </Reader>
                                </ext:Store>
                            </Store>
                            <Triggers>
                                <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                            </Triggers>
                            <Listeners>
                                <Select Handler="this.triggers[0].show();" />
                                <BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                <TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
                            </Listeners>
                        </ext:ComboBox>
                    </Items>
                </ext:Container>
                <ext:TextField ID="txtGhiChu" runat="server" Width="300" FieldLabel=" Ghi chú" />
            </Items>
        </ext:Container>
    </Items>
    <Buttons>
        <ext:Button ID="btnSave" runat="server" Text="Lưu" Icon="Disk">
            <Listeners>
                <Click Handler=" return Validate();  " />
            </Listeners>
            <DirectEvents>
                <Click OnEvent="btnSave_Click">
                </Click>
            </DirectEvents>
        </ext:Button>
        <ext:Button ID="Button1" runat="server" Text="Đóng" Icon="Cancel">
            <Listeners>
                <Click Handler="#{wdAddNewToChuc}.hide();" />
            </Listeners>
        </ext:Button>
    </Buttons>
</ext:Window>
<uc:UCLookUpDiaChi ID="UCLookUpDiaChi" runat="server"></uc:UCLookUpDiaChi>
<uc:UCLookUpToChucHanhChinh ID="UCLookUpToChucHanhChinh1" runat="server"></uc:UCLookUpToChucHanhChinh>
